Usuario:Lord Dhaos/pywikipedia setup
These instructions work with the version current on the pywikipedia download server as of Sept. 2007. I have noticed some instructions for older versions of pywikipedia which do not work due to changes in the way families work. Also, this is a cross platform tool- it runs on Macs and Unix boxes. The following has some notations in regards to Windows boxes, but there is nothing here dependent on Windows to run. Perhaps the help can be made cross platform notes (eg how to run things from a command line, folder notation etc.) by anyone with a linux or apple box. Please feel free to change/ improve this help text. I am perhaps too familiar with the system to know what parts require further explanation. RCCOOP 18:39, 20 September 2007 (UTC) Quick refresher to Pywikipedia if you are already set up *Editor: You use Idle- Python Gui to edit files. You will find this on the start menu->programs->Python2.5->IDLE. It's a good idea to use it rather than something else, because other text editors can mess up the indentation or Unicode characters. *Python is odd in that indentation is meaningful. You can break a script simply by inserting a tab or space in error. Be careful with indents. *How to run: *#Click on desktop icon for “Idle- Python GUI”- looks like a snake *#Open module something. Something could be: *#:Test1.py *#Hit F5 to run, or select menu option “Run” *How to run from the command line: **In the directory C:\Python25\pywikipedia type: **:..\python.exe test1.py *How to find stuff **highlight text you want to look for in all files. Select Edit->find in files Alt-F3. Setup gotchas *You have to run login at least once per wiki site. IF YOU FORGET THIS- PYWIKIPEDIA will appear to work, but do stuff like refuse to save, then spit out a bunch of debugging information including html. You might assume your installation is bad or you downloaded a buggy version. Nope. You aren't logged in. That's all. Check your pywikipedia\login-data directory. If you do not see a file genealogy-en-YOURUSERNAME-login.data, then you need to run login. CD to the pywikipedia directory. Then type login.py -family:genealogy -lang:en. You should then see the above login.data file in your login directory. Common operations examples Operands for all commands are documented in the header of each file- eg category.py or replace.py. Play with them, but try them on single pages before doing a global search and replace. Panic button- if a bot run starts and you want to quickly abort it, Just close the window- the cmd window or the IDLE window. Cat move *..\python.exe category.py move "-from:Lists of People by Surname" "-to:Surnames" Regular expressions example You can search and replace text. Here's a simple example. From the command line: C:\Python25\pywikipedia>..\python replace.py -page:User:OttoBot Errror Error What it does: Loads up only the page User:OttoBot. Changes everything matching Errror to Error. Naturally, Python supports regular expressions and very complicated transformations are possible. Following seems to be broken in latest release "Even number of parameters required": Now say you want to do a bunch of regular expression changes. Create the following file and name it test1.py: import replace import sys import login sys.argv.append('-pass:yourpasswordhere') login.main() sys.argv.append('-page:User:RCCOOP') sys.argv.append('-fix:syntax-safe') replace.main() Hit F5 and watch it party on the page. Installation and configuration :1. Download and install Python (either 2.5 or 2.4 is fine) :2. Download Pywikipedia and install as a subdirectory of your python directory eg C:\Python25\pywikipedia :3. It needs to know how to log onto your wikia. You need to add what is known as a family file. This is done by adding a sitename.py file to the family subdirectory. EG. In the case of Genealogy wikia, you make a file C:\Python25\pywikipedia\families\genealogy_family.py. You will notice the following is exactly like other files in this directory with the only difference those portions highlighted in red.: # -*- coding: utf-8 -*- import family # wikia kvk class Family(family.Family): def __init__(self): family.Family.__init__(self) self.name='kvky' self.langs = { 'es': 'kidvskat.wikia.com', } self.namespaces4 = { '_default': self.namespaces[4'_default'], } self.namespaces5 = { '_default': vs Kat talk', self.namespaces[5'_default'], } def version(self, code): return "1.10" def path(self, code): return '/wiki/index.php' :4. Tell Pywikipedia which wiki to log onto. For this, you change entries in your user-config.py file (EG location C:\Python25\pywikipedia\user.config.py). I just make up one for each wiki I use- commons, wikipedia, and genealogy and copy then to user.config.py and save when I want to switch. Or you could comment strings out. Whatever. The file should look like this. Change "RCCOOP" to your bot name. Change "genealogy" if using with a different wikia. This string must match the one you specified in the Family file in step 3. mylang = 'en' family = 'genealogy' usernames'genealogy''en' = u'RCCOOP' console_encoding = 'utf-8' :5. You should be good to go. If you skip login, you may fail on your first try. See the example Test1.py script example in the "Using pywiki" section.